package com.xliang.spider.version03.quartz.base;

import org.apache.log4j.Logger;

/**
 * 定时任务抽象服务类
 *
 * @author xiongl
 * @create 2016-06-13 16:21
 */
public abstract class AbstractJobService
{
    private static Logger logger = Logger.getLogger(AbstractJobService.class);
    
    abstract public String getDescription();
    
    abstract public void doExecute()
        throws Exception;
        
    public void execute()
    {
        long startAt = System.currentTimeMillis();
        logger.info(getDescription() + " - 开始");
        try
        {
            doExecute();
            long endAt = System.currentTimeMillis();
            logger.info(getDescription() + " - 结束。耗时" + (endAt - startAt) + "毫秒");
        }
        catch (Exception e)
        {
            long endAt = System.currentTimeMillis();
            logger.error(getDescription() + " - 异常终止。耗时：" + (endAt - startAt) + "毫秒", e);
        }
    }
}
